/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.sadhar.sipp.perekamankelompokkegiatanpopup;

import org.sadhar.sia.framework.ClassApplicationModule;
import org.sadhar.sipp.perekamankelompokkegiatan.PerekamanKelompokKegiatan;
import org.sadhar.sipp.perekamankelompokkegiatan.PerekamanKelompokKegiatanDAO;
import org.sadhar.sipp.perekamankelompokkegiatan.PerekamanKelompokKegiatanDAOImpl;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;

/**
 *
 * @author hendro
 */
public class KelompokKegiatanPopupWnd extends ClassApplicationModule {

    private Listbox lstboxKelompokKegiatan;
    private Textbox txtboxKeySearch;
    private PerekamanKelompokKegiatanDAO kelompokKegiatanDAO;

    public KelompokKegiatanPopupWnd() {
        this.kelompokKegiatanDAO = new PerekamanKelompokKegiatanDAOImpl();
    }

    public void onCreate() throws Exception {
        lstboxKelompokKegiatan = (Listbox) getFellow("lstboxKelompokKegiatan");
        txtboxKeySearch = (Textbox) getFellow("txtboxKeySearch");
        load();
    }

    public void load() throws Exception {
        int no = 1;
        lstboxKelompokKegiatan.getItems().clear();
        for (PerekamanKelompokKegiatan kel : kelompokKegiatanDAO.list(txtboxKeySearch.getValue())) {
            Listitem item = new Listitem();
            item.setValue(kel);
            item.appendChild(new Listcell(String.valueOf(no++)));
            item.appendChild(new Listcell(kel.getKelompokKegiatan()));
            lstboxKelompokKegiatan.appendChild(item);
        }
    }

    public void lstboxKelompokKegiatanOnSelect() throws Exception {
        Window window = (Window) this.getRoot().getFellow("contentDiv").getFirstChild();
        Textbox txtboxKelompokKegiatan = (Textbox) window.getFellow("txtboxKelompokKegiatan");
        Textbox txtboxKodeKelompokKegiatan = (Textbox) window.getFellow("txtboxKodeKelompokKegiatan");
        PerekamanKelompokKegiatan kel = (PerekamanKelompokKegiatan) lstboxKelompokKegiatan.getSelectedItem().getValue();
        txtboxKelompokKegiatan.setValue(kel.getKelompokKegiatan());
        txtboxKodeKelompokKegiatan.setValue(kel.getKodeKelompok() + "");
        this.detach();
    }
}
